package logic

import (
	"context"
	"hosp/hosprpc/hosprpc"

	"hosp/api/internal/svc"
	"hosp/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PatientAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPatientAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PatientAddLogic {
	return &PatientAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PatientAddLogic) PatientAdd(req *types.PatientAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.HospRpc.PatientAdd(l.ctx, &hosprpc.PatientAddRequest{
		Name:       req.Name,
		IdCard:     req.IdCard,
		NickName:   req.NickName,
		Address:    req.Address,
		CardNumber: req.CardNumber,
		IdNumber:   req.IdNumber,
		Tel:        req.Tel,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    nil,
			Data:    500,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    add,
		Data:    200,
	}, nil
}
